import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:full_display/common/global.dart';
import 'package:full_display/common/qxp_color.dart';
import 'package:full_display/common/qxp_style.dart';
import 'package:full_display/page/montage/montage_page_old.dart';
import 'package:full_display/page/montage/montage_provider.dart';
import 'package:full_display/provide/bluetooth_provider.dart';
import 'package:full_display/provide/button_list_provider.dart';
import 'package:full_display/provide/button_counter.dart';
import 'package:full_display/provide/cmd_provider.dart';
import 'package:full_display/provide/drawer_provider.dart';
import 'package:full_display/provide/media_provider.dart';
import 'package:full_display/provide/radio_state_provider.dart';
import 'package:full_display/provide/time_provider.dart';
import 'package:full_display/routers/route_name.dart';
import 'package:full_display/unit/widgets/widget_global/custom_behavior.dart';
import 'package:provider/provider.dart';
import 'package:full_display/unit/navigation/navigation_util.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'generated/l10n.dart';
import 'splash_page.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  if (Platform.isAndroid) {
    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarIconBrightness: Brightness.light));
  }
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp({super.key});

  final botToastBuilder = BotToastInit();
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider<ButtonCounter>(create: (_) => ButtonCounter()),
        ChangeNotifierProvider<ButtonListProvider>(
            create: (_) => ButtonListProvider()),
        ChangeNotifierProvider<RadioStateProvider>(
            create: (_) => RadioStateProvider()),
        ChangeNotifierProvider<TimeProvider>(create: (_) => TimeProvider()),
        ChangeNotifierProvider<BluetoothProvider>(
            create: (_) => BluetoothProvider()),
        ChangeNotifierProvider<DrawerProvider>(create: (_) => DrawerProvider()),
        ChangeNotifierProvider<CMDProvider>(create: (_) => CMDProvider()),
        ChangeNotifierProvider<MediaVideoProvider>(
            create: (_) => MediaVideoProvider()),
        ChangeNotifierProvider<MontageProvider>(
            create: (_) => MontageProvider()),
      ],
      child: MaterialApp(
        scrollBehavior: CustomBehavior(),
        navigatorKey: Global.navigatorKey,
        localizationsDelegates: const [
          S.delegate,
          GlobalMaterialLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate
        ],
        //Text(S.of(context).title(17))
        supportedLocales: S.delegate.supportedLocales,
        localeResolutionCallback: (locale, supportedLocales) {
          print("locale=====>${locale}");
          // 如果语言是英语
          if (locale?.languageCode == 'en') {
            //注意大小写，返回美国英语
            return const Locale('en', 'US');
          } else {
            return locale;
          }
        },
        navigatorObservers: [NavigationUtil.getInstance()],
        routes: NavigationUtil.configRoutes,
        debugShowCheckedModeBanner: false,
        title: '全熄屏',
        builder: (context, child) {
          child = MediaQuery(
              data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
              child: child!);
          child = botToastBuilder(context, child);
          return child;
        },
        theme: ThemeData(
            fontFamily: 'Sumscope',
            appBarTheme: const AppBarTheme(
              systemOverlayStyle: SystemUiOverlayStyle(
                systemNavigationBarColor: Color(0xFF000000),
                systemNavigationBarDividerColor: null,
                statusBarColor: null,
                systemNavigationBarIconBrightness: Brightness.light,
                statusBarIconBrightness: Brightness.light,
                statusBarBrightness: Brightness.dark,
              ),
            ),
            brightness: Brightness.light,
            hintColor: Colors.black,
            primaryColor: ColorPlate.black,
            scaffoldBackgroundColor: ColorPlate.black,
            dialogBackgroundColor: ColorPlate.black,
            dialogTheme: DialogTheme(backgroundColor: ColorPlate.black),
            splashColor: Colors.transparent,
            highlightColor: Colors.transparent),
        initialRoute: RouteNames.splash,
      ),
    );
  }
}
